/**
 * Copyright (C) 2021 - 2031 O-Cubes Co., Ltd.
 */

/****************************************************************
 *  @file    sfud.h
 *  @brief   Header File of SFUD
 *  @version v1.0
 *  @date    03. Apr. 2023
 *  @author  gonght
 ****************************************************************/

#ifndef __SFUD_H__
#define __SFUD_H__

#include <stdint.h>
#include "sfud_def.h"
#include "common.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
 * SFUD library initialize.
 *
 * @return result
 */
sfud_err sfud_init(void);

/**
 * read flash data
 *
 * @param addr start address
 * @param size read size
 * @param data read data pointer
 *
 * @return result
 */
sfud_err sfud_read(uint32_t addr, size_t size, uint8_t *data);

/**
 * erase flash data
 *
 * @note It will erase align by erase granularity.
 *
 * @param addr start address
 * @param size erase size
 *
 * @return result
 */
sfud_err sfud_erase(uint32_t addr, size_t size);

/**
 * write flash data (no erase operate)
 *
 * @param addr start address
 * @param data write data
 * @param size write size
 *
 * @return result
 */
sfud_err sfud_write(uint32_t addr, size_t size, const uint8_t *data);

/**
 * erase and write flash data
 *
 * @param addr start address
 * @param size write size
 * @param data write data
 *
 * @return result
 */
sfud_err sfud_erase_write(uint32_t addr, size_t size, const uint8_t *data);

/**
 * erase all flash data
 *
 * @param flash flash device
 *
 * @return result
 */
sfud_err sfud_chip_erase(void);

/**
 * read flash register status
 *
 * @param status register status
 *
 * @return result
 */
//sfud_err sfud_read_status(uint8_t cmd_byte, uint8_t *status, uint8_t r_len);

/**
 * write status register
 *
 * @param is_volatile true: volatile mode, false: non-volatile mode
 * @param status register status
 *
 * @return result
 */
//sfud_err sfud_write_status(bool is_volatile, uint8_t cmd_byte, uint8_t *status, uint8_t w_len);

/* get flash manufacturer ID*/
//uint8_t sfud_get_mf_id(void);

void sfud_xip_en(void);

void sfud_xip_dis(void);

#ifdef __cplusplus
}
#endif

#endif /* __SFUD_H__ */
